﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using System;
using System.ComponentModel;

namespace Property.Subscriptions
{
    public abstract class Subscription<T> : IDisposable
    {
        public Subscription(IProperty<T> property)
        {
            if (property == null) throw new ArgumentNullException("property");

            _Property = property;
            _Property.PropertyChanging += _Property_PropertyChanging;
            _Property.PropertyChanged += _Property_PropertyChanged;
        }

        //=//

        protected readonly IProperty<T> _Property;

        protected virtual void _Property_PropertyChanged(object sender, PropertyChangedEventArgs e) 
        { }

        protected virtual void _Property_PropertyChanging(object sender, PropertyChangingEventArgs e) 
        { }

        //=//

        void IDisposable.Dispose()
        {
            _Property.PropertyChanging -= _Property_PropertyChanging;
            _Property.PropertyChanged -= _Property_PropertyChanged;
        }
    }
}
